package com.haiyu.manager.controller.platform;

import com.haiyu.manager.dto.UserInfoSearchDTO;
import com.haiyu.manager.pojo.UserInfo;
import com.haiyu.manager.response.PageDataResult;
import com.haiyu.manager.service.UserInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("userInfo")//指定路由
public class UserInfoController {
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    UserInfoService userInfoService;

    /**
     *
     * 功能描述: 跳到userInfo列表
     *
     *
     */
    @RequestMapping("/userInfoManage")
    public String boardManage() {
        return "/userInfo/userInfoManage";
    }

    /**
     *
     * 功能描述: 分页查询userInfo列表
     *
     *
     */
    @RequestMapping(value = "/getUserInfoList", method = RequestMethod.POST)
    @ResponseBody
    public PageDataResult getBoardList(@RequestParam("pageNum") Integer pageNum,
                                       @RequestParam("pageSize") Integer pageSize,/*@Valid PageRequest page,*/ UserInfoSearchDTO userInfoSearch) {
        /*logger.info("分页查询用户列表！搜索条件：userSearch：" + userSearch + ",pageNum:" + page.getPageNum()
                + ",每页记录数量pageSize:" + page.getPageSize());*/
        System.out.println(userInfoSearch);
        PageDataResult pdr = new PageDataResult();
        try {
            if(null == pageNum) {
                pageNum = 1;
            }
            if(null == pageSize) {
                pageSize = 10;
            }
            // 获取用户列表
            pdr = userInfoService.getUserInfoList(userInfoSearch, pageNum ,pageSize);
            logger.info("userInfo列表查询=pdr:" + pdr);

        } catch (Exception e) {
            e.printStackTrace();
            logger.error("userInfo列表查询异常！", e);
        }
        return pdr;
    }




    /**
     *
     * 功能描述: 删除/恢复
     *
     */
    @PostMapping("updateUserLabel")
    @ResponseBody
    public Map<String,Object> updateUserLabel(@RequestParam("buyerOpenid") String buyerOpenid,@RequestParam("userInfoLabel") Integer userInfoLabel) {
        logger.info("删除/恢复！buyerOpenid:" + buyerOpenid+" userInfoLabel:"+userInfoLabel);
        Map<String, Object> data = new HashMap<>();
        if(userInfoLabel == 1){
            //删除
            data = userInfoService.delUser(buyerOpenid,userInfoLabel);
        }else{
            //恢复
            data = userInfoService.recoverUser(buyerOpenid,userInfoLabel);
        }
        return data;
    }


}
